package com.tlias.exam.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.tlias.exam.mapper.GoogMapper;
import com.tlias.exam.pojo.Goods;
import com.tlias.exam.pojo.PageResult;
import com.tlias.exam.pojo.QueryGoodsDTO;
import com.tlias.exam.service.GoogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

/**
 * TODO
 *
 * @Author mr.luo
 * @Date 29 4月 2025 16:24
 */
@Service
public class GoogServiceImpl implements GoogService {
    @Autowired
    private GoogMapper googMapper;

    @Override
    public PageResult queryGoods(QueryGoodsDTO queryGoodsDTO) {
     PageHelper.startPage(queryGoodsDTO.getPage(), queryGoodsDTO.getPageSize());
        Page<Goods> page = googMapper.queryGoods(queryGoodsDTO);
        return new PageResult(page.getTotal(), page.getResult());
    }


    @Override
    public Goods getGoodsXJ(Integer id) {
        Goods goods = googMapper.getGoodsXJ(id);
        return goods;
    }

    @Override
    public void addGoods(Goods goods) {
        goods.setStart(LocalDateTime.now());
        goods.setEnd(LocalDateTime.now());
        googMapper.addGoods(goods);
    }


    @Override
    public void updateGoods(Goods goods) {
        goods.setEnd(LocalDateTime.now());
        googMapper.updateGoods(goods);
    }

    @Override
    public void deleteGoods(List<Integer> ids) {
        googMapper.deleteGoods(ids);
    }
}
